import java.util.Arrays;
import java.util.Scanner;

public class Test3 {
    public static void main(String[] args) {

    }
    public static String myTostring(int[] array){
        if(array == null){//先判断array是不是为null!!!
            return "null";
        }
        String ret = "[";
        for (int i = 0; i < array.length; i++) {
            ret += array[i];
            if(i != array.length -1)
                 ret += ",";
        }
        ret += "]";
        return ret;
    }
    public static void main8(String[] args) {
        int[] array = {1,2,3,4};//[1,2,3,4]
        System.out.println(myTostring(array));
    }
    public static int[] func(){
        int[] tmp = {1,2,3,4};
        return tmp;
    }
    public static void main7(String[] args) {
        int[] array = func();
        System.out.println(Arrays.toString(array));
    }
    public static void swap(int[] array){
        int tmp = array[0];
        array[0] = array[1];
        array[1] = tmp;
    }
    public static void main6(String[] args) {
       /* int a = 10;
        int b = 20;
        //swap() 拿不到栈上的地址，无法进行交换*/
        //只能拿到堆上的地址
        int[] array = {10,20};
        swap(array);
        for (int x:array) {
            System.out.print(x+" ");
        }
    }
    public static void main5(String[] args) {
        int[] array = null;
        System.out.println(array);
    }
    public static void transform(int[] array){
        for (int i = 0; i < array.length; i++) {
            array[i] *= 2;
        }
    }
    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = scanner.nextInt();
        }
        transform(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main3(String[] args) {
        int[] array = {1,2,3,4};
        for (int x:array) {
            System.out.print(x*2+" ");
        }
        System.out.println();
        for (int i = 0; i < array.length; i++) {
            array[i] *= 2;
            System.out.print(array[i]+" ");
        }
        System.out.println();
        transform(array);
        System.out.println(Arrays.toString(array));
    }
    public static void main1(String[] args) {
        int[] array = new int[5];
        int[] array2 = new int[]{1,2,3};
        int[] array3 = {1,2,3};
        int[] array4;//没分配内存
        array4 = new int[6];//只分配内存，没初始化
        int[] array5;
        array5 = new int[]{1,2,3,4,5};
    }

    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5,6};
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]+" ");
        }
        System.out.println();
        for (int x:array) {
            System.out.print(x+" ");
        }
        System.out.println();
        System.out.println(Arrays.toString(array));
    }

}
